
#include <BIndexArray>
#include <BElement>
#include "member_BElement.h"

using namespace BWE;

#define member					(*(member_BElement*)_ptr)
#define member_allocate()		_ptr = new member_BElement(this)
#define member_release()		delete (member_BElement*)_ptr

BElement::BElement()
{
	member_allocate();
}
BElement::BElement(Primitive primitive, int first, int count)
{
	member_allocate();
	member.primitive = primitive;
	member.first = first;
	member.count = count;
}
BElement::BElement(Primitive primitive, BIndexArray* indices)
{
	member_allocate();
	member.primitive = primitive;
	member.first = 0;
	if (indices)
	{
		member.count = indices->size();
		member.indices = indices;
	}
}
BElement::~BElement()
{
	member_release();
}

void BElement::set(Primitive primitive, int first, int count)
{
	member.primitive = primitive;
	member.first = first;
	member.count = count;
}

void BElement::setPrimitive(Primitive primitive)
{
	if (member.primitive != primitive)
	{
		member.primitive = primitive;
	}
}
Primitive BElement::primitive() const
{
	return member.primitive;
}

void BElement::setFirst(int first)
{
	if (member.first != first)
	{
		member.first = first;
		if (member.first < 0)
			member.first = 0;
	}
}
int BElement::first() const
{
	return member.first;
}

void BElement::setCount(int count)
{
	if (member.count != count)
	{
		member.count = count;
		if (member.count < 0)
			member.count = 0;
	}
}
int BElement::count() const
{
	return member.count;
}

void BElement::setIndices(BIndexArray* indices)
{
	member.indices = indices;
}
BIndexArray* BElement::indices() const
{
	return member.indices;
}
